package com.rraj.common.mq.mqenum;

/**
 * TOPIC枚举 一个TOPIC对应一个枚举
 *
 * @author WangSheng
 * @date 2017/06/19
 */
public enum MQTopicEnum {
    TOPIC_DEFAULT(1, "TOPIC_SHARDING_ORDER", "DEFAULT", "TOPIC_SHARDING_ORDER", "存储普通消息"),
    TOPIC_TRANSACTION(2, "TOPIC_TRANSACTION", "TRANSACTION", "TOPIC_TRANSACTION", "存储事务消息"),
    TOPIC_ALL_ORDER(3, "TOPIC_ALL_ORDER", "ALL_ORDER", "TOPIC_ALL_ORDER", "存储全局顺序消息"),
    TOPIC_SHARDING_ORDER(1, "TOPIC_SHARDING_ORDER", "DEFAULT", "TOPIC_SHARDING_ORDER", "存储分区顺序消息") ;
    /**
     * 唯一标识
     */
    private int id;
    /**
     * code
     * 命名格式：TOPIC_TOPIC名称
     */
    private String code;
    /**
     * topic类型
     * 类型如下：
     * DEFAULT:存储无序、定时、延时类型的消息
     * TRANSACTION：存储事务消息
     * ALL_ORDER：存储全局顺序消息
     * SHARDING：存储分区顺序消息
     */
    private String type;
    /**
     * 阿里云MQ上topic的名称
     */
    private String topic;
    /**
     * 描述
     */
    private String desc;

    MQTopicEnum(int id, String code, String type, String topic, String desc) {
        this.id = id;
        this.code = code;
        this.type = type;
        this.topic = topic;
        this.desc = desc;
    }

    public static MQTopicEnum getEnumById(int id) {
        for (MQTopicEnum c : MQTopicEnum.values()) {
            if (c.getId() == id) {
                return c;
            }
        }
        return null;
    }
    public static MQTopicEnum getEnumByCode(String code) {
        for (MQTopicEnum c : MQTopicEnum.values()) {
            if (c.getCode().equals(code)) {
                return c;
            }
        }
        return null;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getTopic() {
        return topic;
    }

    public void setTopic(String topic) {
        this.topic = topic;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }
}
